package com.ashen.study.aop.dynamic;

import com.ashen.study.aop.patterns.impl.SubjectImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author hxl
 * @Classname JDkProxySubject
 * @Description jdk动态代理
 * @Date 2019/9/24 16:49
 */
public class JDkProxySubject implements InvocationHandler {

    private SubjectImpl subject;

    public JDkProxySubject(SubjectImpl subject) {
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before.....................");
        Object result = null;
        try {
            result = method.invoke(subject,args);
        }catch (Exception e){
            System.out.println("exception.....................");
        }finally {
            System.out.println("finally ..........................");
        }
        return result;
    }
}
